import request from '@/commons/libraries/request'

export default {
  async gets (status = '') {
    try {
      let url = '/setting/sys/role/gets/' + (status !== '' ? (status + '/') : '')
      const ret = await request(url, {})
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async get (id) {
    try {
      const ret = await request('/setting/sys/role/get/', {
        id: id
      })
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async getMenus () {
    try {
      const ret = await request('/setting/sys/role/getMenus/', {})
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async add (role, menus) {
    try {
      const ret = await request('/setting/sys/role/add/', {
        role: role,
        menus: menus
      })
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async update (role, menus) {
    try {
      const ret = await request('/setting/sys/role/update/', {
        role: role,
        menus: menus
      })
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  }
}
